package com.example.myprojectoffeixue;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by ASUS on 2016/10/27.
 */
public class SelectAdapter extends BaseAdapter {

    int[] ImageIDs;
    String[] nameStr;
    private LayoutInflater layoutInflater;
    private Context context;


    public SelectAdapter(int[] ImageIDs, Context context, String[] nameStr) {
        super();
        this.ImageIDs = ImageIDs;
        this.nameStr = nameStr;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return ImageIDs.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return ImageIDs[position];
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder h = null;
        if (convertView == null) {
            h = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.select_item, null);
            h.tv = (TextView) convertView.findViewById(R.id.tv_listview);
            h.iv = (ImageView) convertView.findViewById(R.id.iv_listview);
            h.iv1 = (ImageView) convertView.findViewById(R.id.iv1_listview);
            convertView.setTag(h);
        } else {
            h = (ViewHolder) convertView.getTag();
        }

        h.tv.setText(nameStr[position]);
        h.iv.setImageResource(ImageIDs[position]);
        h.iv1.setImageResource(R.drawable.button_youjiantou);

        return convertView;
    }

    class ViewHolder {

        TextView tv;
        ImageView iv;
        ImageView iv1;

    }


}